/*
* @Author: obsidian
* @Date:   2016-03-20 08:44:40
* @Last Modified by:   obsidian
* @Last Modified time: 2016-04-22 09:09:57
*/
#include "menu_gpsteer.h"
#include "../lcd_global.h"
#include "../lcd.h"
#include "module/gpsteer/gpsteer.h"
static void menu_gpsteer_init(void *parg);
static void menu_release_exec(void* parg);
static void menu_hold_exec(void* parg);
struct Item gpsteer_i[MAX_ITEM_NUM] = 
{
    //ctx               id  flag   isint color int float pos
    {.ctx = "ccr",      .id = 1,  .ctx_len = 4,  .flag = FILE,  .value_type = INTEGER, .p_value = (void *)&TIM2->CCR4,          .func_enter = nop, input,  nop,    nop},
    {.ctx = "midv0",    .id = 2,  .ctx_len = 5,  .flag = FILE,  .value_type = INTEGER, .p_value = (void *)&gpsteer.midvalue0,    .func_enter = nop, input,  nop,    nop},
	{.ctx = "midvl",    .id = 3,  .ctx_len = 5,  .flag = FILE,  .value_type = INTEGER, .p_value = (void *)&gpsteer.midvalue1,    .func_enter = nop, input,  nop,    nop},		
    {.ctx = "limit",    .id = 4,  .ctx_len = 5,  .flag = FILE,  .value_type = INTEGER, .p_value = (void *)&gpsteer.limit[0],    .func_enter = nop, input,  nop,    nop},    
    {.ctx = "status",   .id = 5,  .ctx_len = 6,  .flag = FILE,  .value_type = INTEGER, .p_value = (void *)&gpsteer.status,      .func_enter = nop, input,  nop,    nop},
    {.ctx = "hold",     .id = 6,  .ctx_len = 4,  .flag = FILE,  .value_type = NONE, .p_value = 0,                               .func_enter = nop, menu_hold_exec,      nop,    nop},
    {.ctx = "release",  .id = 7,  .ctx_len = 7,  .flag = FILE,  .value_type = NONE, .p_value = 0,                               .func_enter = nop, menu_release_exec,  nop,    nop},
};

struct Node gpsteer_n = 
{
    // .itemnum            =   sizeof(gpsteer_i) / sizeof(gpsteer_i[0]),
    // .page_num           =   (unsigned short)sizeof(gpsteer_i) / sizeof(gpsteer_i[0])/PAGE_SIZE,
    .page_index         =   0,
    .node_id            =   1,
    .p_item             =   gpsteer_i,
    .position           =   {0, 0},
    .parent             =   &control_n,
    .child              =   {0},
    .init               =   menu_gpsteer_init
};

static void menu_gpsteer_init(void *parg)
{
    unsigned char i = 0;
    for(i = 0;i < MAX_ITEM_NUM;i ++)
    {
        if(gpsteer_i[i].ctx[0] == 0){break;}
        gpsteer_n.itemnum ++;
    }
    gpsteer_n.page_num = gpsteer_n.itemnum / PAGE_SIZE;

    gpsteer_n.p_item[0].p_value = (void *)&TIM2->CCR4;
    gpsteer_n.save = gpsteer.save;
}

static void menu_hold_exec(void* parg)
{
    gpsteer.hold();
}
static void menu_release_exec(void* parg)
{
    gpsteer.release();
}
